package com.alibaba.agile;

import java.util.ArrayList;
import java.util.List;

public class BookBasket {
	private List<BookItem> bookItemList = new ArrayList<BookItem>();

	public void add(Book book, int count) {
		BookItem bookItem = new BookItem(book, count);
		bookItemList.add(bookItem);
	}

	public List<BookItem> getBookItemList() {
		return this.bookItemList;
	}

	public boolean removeBook(Book jobs, int count) {
		for (int i = 0; i < bookItemList.size(); i++) {
			BookItem b = bookItemList.get(i);
			if (b.getBook().equals(jobs)) {

				int c = b.getCount();
				if (c > count) {
					b.setCount(c - count);
				} else if (c == count) {
					bookItemList.remove(b);
				} else {
					return false;
				}

			}

		}
		return true;

	}

	public int totalNums() {
		int res = 0;
		for (BookItem item : bookItemList) {

			res += item.getCount();

		}

		return res;

	}

}
